package org.elena.model.filter;

import org.apache.commons.collections4.CollectionUtils;
import org.elena.model.exception.ActivityException;
import org.elena.model.result.MatchResult;
import org.elena.model.result.Result;
import org.elena.model.sample.Sample;

public class OrFilter extends LogicFilter {

    @Override
    public Result doFilter(Sample sample) {
        if (CollectionUtils.isEmpty(filterList)) {
            return new MatchResult() {{
                setSuccess(true);
            }};
        }
        return new MatchResult() {{
            setSuccess(filterList.stream().anyMatch(filter -> {
                try {
                    return filter.doFilter(sample).success();
                } catch (ActivityException e) {
                    return false;
                }
            }));
        }};
    }
}
